package com.hfut.wxy.common.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hfut.wxy.common.design.DataExChange;
import com.hfut.wxy.common.parent.WxyBase;
import com.hfut.wxy.common.parent.WxyId;
import org.springframework.util.CollectionUtils;

import java.util.List;

public class ExchangeUtil {

    public static <T extends WxyId> JSONArray changeListToJSON(List<T> list, DataExChange dataExChange){
        if (CollectionUtils.isEmpty(list)){
            return null;
        }
        JSONArray re = new JSONArray();
        JSONObject info;
        for (WxyId t : list) {
            info = new JSONObject();
            dataExChange.exchange(info,t);
            re.add(info);
        }
        return re;
    }
}
